'''
import time
from selenium import webdriver # pip3 install selenium

driver = webdriver.Chrome('/Users/teacher/Documents/chromedriver')  # Optional argument, if not specified will search path.
driver.get('https://www.baidu.com/');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('wd')
search_box.send_keys('吉林师范大学')
search_box.submit()
time.sleep(10) # Let the user actually see something!
driver.quit()
'''

# import time

# from selenium import webdriver
# from selenium.webdriver.chrome.service import Service

# service = Service('/Users/teacher/Documents/chromedriver')
# service.start()

# driver = webdriver.Remote(service.service_url)
# url = 'https://list.jd.com/list.html?cat=9987,653,655'
# driver.get(url);
# html =  driver.page_source

import time
from selenium import webdriver # pip3 install selenium

option = webdriver.ChromeOptions()
option.add_argument('headless')   # 添加 headless 选项，提高运行效率
driver = webdriver.Chrome('/Users/teacher/Documents/chromedriver', options=option)  # Optional argument, if not specified will search path.
driver.get('https://list.jd.com/list.html?cat=9987,653,655');

J_goodsList = driver.find_element_by_id('J_goodsList')
cell_phones = J_goodsList.find_elements_by_class_name('gl-item')

phones = []
for phone in cell_phones:
    cell_phone = {}
    cell_phone['name'] = phone.find_element_by_class_name('p-name-type-3').find_element_by_tag_name('em').text
    
    cell_phone['price'] = phone.find_element_by_class_name('p-price').text
    
    cell_phone['img'] = phone.find_element_by_class_name('p-img').find_element_by_tag_name('img').get_attribute('data-lazy-img')
    phones.append(cell_phone)
driver.quit()

print(len(phones), phones[1])